import urllib.request
import random
iplist=['58.222.254.11:3128','61.185.219.126:3128','218.247.161.37:80','61.172.249.96:80']
url='http://www.ip138.com'
proxy_support=urllib.request.ProxyHandler({'http':random.choice(iplist)})
opener=urllib.request.build_opener(proxy_support)
opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 115Browser/8.1.0')]
# opener.open(url) #创建临时opener
urllib.request.install_opener(opener)#替换系统默认opener
# req=urllib.request.Request(url,data,header)
# req.add_header()
response=urllib.request.urlopen(url)
html=response.read().decode('utf-8')
print(html)
